package com.ebelter.bodyfatscale.util;

import android.text.TextUtils;

/**
 * Created by pan on 2018/4/2
 */

public class NumUtils {

    /**
     * 把字符串转换为int
     */
    public static int string2Int(String numStr){
      return string2Int(numStr,0);
    }

    public static int string2Int(String numStr,int defaultValue){
        if (TextUtils.isEmpty(numStr)){
            return defaultValue;
        }
        try {
            return Integer.parseInt(numStr);
        }catch (Exception e){
            return defaultValue;
        }
    }

    /**
     * 把字符串转换为int
     */
    public static float string2Float(String numStr){
        if (TextUtils.isEmpty(numStr)){
            return 0;
        }
        try {
            return Float.parseFloat(numStr);
        }catch (Exception e){
            return 0;
        }

    }



    //数字保留位
    public static float numBaoLiuWei(float value,int baoliuwei) {
        float num=(float)((Math.round(value*10))/10.0);;//如果要求精确4位就*10000然后/10000
        return num;
    }



}
